import { createKeywordModel } from '../../models/keyword';

const keywordModel = createKeywordModel();

Component({
  mixins: [],
  data: {
    historyWords: [],
    searchResult: [],
    keyword: '',
    hasSearch: false,
    hasMore: true,
  },
  props: {},
  didMount() {
    const historyWords = keywordModel.getHistoryWords();
    this.setData({ historyWords });
  },
  methods: {
    onCancel() {
      this.props.onCancel();
    },
    onConfirm(event) {
      this.setData({ hasSearch: true });
      let keyword = event.detail.value;
      if (!keyword) return;
      keyword = keyword.trim();
      this.setData({ keyword });
      keywordModel.addToHistoryWords(keyword);
    },
    onDelete() {
      this.setData({
        hasSearch: false,
      });
      this._initializeData();
    },
    onLower() {
      
    },
    _initializeData() {
      this.setData({
        searchResult: [],
        keyword: '',
        hasMore: true,
      });
    },
  },
});
